/*
* @Author: Sean
* @Date:   2019-12-09 23:02:12
* @Last Modified by:   Sean
* @Last Modified time: 2019-12-09 23:03:24
*/

const state = {
  resources: {
    models: {

    },
    components: {

    },
    pages: {

    }
  },
  /**
   * 数据存储池
   * @type {Object}
   */
  pool: {},
  /**
   * 窗口管理器
   * @type {Object}
   */
  main: {
    /**
     * 资源管理器
     * @type {Array}
     */
    resources: [],
    /**
     * 控制台
     * @type {Array}
     */
    controls: [],
    /**
     * 操作台
     * @type {Array}
     */
    libraries: [],
    /**
     * 属性台
     * @type {Array}
     */
    attributes: [],
    /**
     * 图层台
     * @type {Array}
     */
    layers: [],
  },
  /**
   * 控件列表-异步加载
   */
  widgets: widgets,
  /**
   * 配置数据
   */
  config: {
    name: "body",
    data: {
      title: "新建页面",
      name: "new_page",
      height: "500px",
      width: "800px",
      type: 'components'
    },
    slot: [],
    regulation: {
      amount: 999,
      level: false,
      scope: ['row']
    },
    components: "",
    attributes: []
  }
}

const mutations = {
  /**
   * 设置资源
   * @param  {[type]} state      [description]
   * @param  {[type]} attributes [description]
   * @return {[type]}            [description]
   */
  set_config: (state, config) => {
    state.config = config;
  },
  /**
   * 设置资源
   * @param  {[type]} state      [description]
   * @param  {[type]} attributes [description]
   * @return {[type]}            [description]
   */
  set_main: (state, main) => {
    state.main.attributes = main.attributes;
    state.main.layers = main.layers;
    state.main.libraries = main.libraries;
  },
  /**
   * 设置资源
   * @param  {[type]} state      [description]
   * @param  {[type]} attributes [description]
   * @return {[type]}            [description]
   */
  set_resources: (state, resources) => {
    state.resources = resources;
  },

  /**
   * 设置资源单个属性
   * @param  {[type]} state         [description]
   * @param  {[type]} options.key   [description]
   * @param  {[type]} options.value [description]
   * @return {[type]}               [description]
   */
  set_resources_attr: (state, { key, value }) => {
    state.resources[key] = value;
  },

  /**
   * 设置属性
   * @param  {[type]} state      [description]
   * @param  {[type]} attributes [description]
   * @return {[type]}            [description]
   */
  set_attributes: (state, attributes) => {
    state.main.attributes = attributes;
  },
  /**
   * 设置控件
   * @param  {[type]} state        [description]
   * @param  {[type]} options.name [description]
   * @param  {[type]} options.data [description]
   * @return {[type]}              [description]
   */
  set_widgets: (state, { name, data }) => {
    state.widgets[name] = data;
  },
  /**
   * 存储池
   * @param  {[type]} state        [description]
   * @param  {[type]} options.name [description]
   * @param  {[type]} options.data [description]
   * @return {[type]}              [description]
   */
  set_pool: (state, { name, data }) => {
    state.pool[name] = data;
  },
  /** 
   * 点击图层
   * @param  {[type]} state      [description]
   * @param  {[type]} attributes [description]
   * @return {[type]}            [description]
   */
  click_layer: (state, { handle, attribute }) => {
    state.main.attributes = [{
      title: "栅格属性",
      components: handle,
      data: attribute
    }]
  },
  /**
   * 选择图层
   * @param  {[type]} state      [description]
   * @param  {[type]} attributes [description]
   * @return {[type]}            [description]
   */
  select_layer: (state, { handle, attribute }) => {
    state.main.attributes = [{
      title: "图层属性",
      components: handle,
      data: attribute
    }]
  },
  /**
   * 导入模型
   * @param  {[type]} state             [description]
   * @param  {[type]} options.handle    [description]
   * @param  {[type]} options.attribute [description]
   * @return {[type]}                   [description]
   */
  import_modelr: (state, { handle, attribute }) => {

  },
  /**
   * 设置控制台属性
   * @param  {[type]} state     [description]
   * @param  {[type]} attribute [description]
   * @return {[type]}           [description]
   */
  set_libraries: (state, attribute) => {
    state.main.libraries[0].attribute = attribute.models
    state.main.libraries[1].attribute = attribute.gather
    state.main.libraries[2].attribute = attribute.actions
  }
}

const actions = {
  setResources({ commit, dispatch }, resources) {
    commit('set_resources', resources);
  },
  setResourcesAttr({ commit }, { key, value }) {
    commit('set_resources_attr', { key, value })
  },
  setConfig({ state, commit, dispatch }, resources) {
    commit('set_config', resources);
  },
  setMain({ state, commit, dispatch }, resources) {
    commit('set_main', resources);
  },
  /**
   * 获取模型数据
   * @param  {[type]} state [description]
   * @return {[type]}       [description]
   */
  getModels: ({ state, commit, dispatch }) => {
    return {
      models: state.resources.models,
      data: state.main.libraries[0].attribute
    }
  },
  /**
   * 获取模型数据
   * @param  {[type]} state [description]
   * @return {[type]}       [description]
   */
  getConfig: ({ state, commit, dispatch }) => {
    return state.config;
  },
  /**
   * 设置仪表盘属性
   * @param  {[type]} options.state    [description]
   * @param  {[type]} options.commit   [description]
   * @param  {[type]} options.dispatch [description]
   * @param  {[type]} attribute        [description]
   * @return {[type]}                  [description]
   */
  setLibraries: ({ state, commit, dispatch }, attribute) => {
    commit('set_libraries', attribute);
  },
  /**
   * 获取仪表盘属性
   * @param  {[type]} options.state    [description]
   * @param  {[type]} options.commit   [description]
   * @param  {[type]} options.dispatch [description]
   * @return {[type]}                  [description]
   */
  getLibraries: ({ state, commit, dispatch }) => {
    return {
      models: state.main.libraries[0].attribute,
      gather: state.main.libraries[1].attribute,
      actions: state.main.libraries[2].attribute
    }
  }
}


export default {
  state,
  mutations,
  actions
}
